<?php
/**
 * DouPHP小程序模块
 * Author: cuihaifeng  qq 366131726 微信同号
 * 网址：www.zbxingke.com www.0533hf.com
 */

/**
 * 读取配置项
 * @param string $key
 * @return array|mixed
 */
function setting_load($key = '') {
    global $_W;
    $cachekey = "setting";
    $settings = cache_load($cachekey);
    if (empty($settings) || DEVELOPMENT) {
        $settings = pdo_fetchall('SELECT * FROM ' . tablename('config'), array(), 'name');
        if (is_array($settings)) {
            foreach ($settings as $k => &$v) {
                $settings[$k] = iunserializer($v['value']);
            }
        }
        cache_write($cachekey, $settings);
    }
    if (!is_array($_W['setting'])) {
        $_W['setting'] = array();
    }
    $_W['setting'] = array_merge($_W['setting'], $settings);
    if (!empty($key)) {
        return array($key => $settings[$key]);
    } else {
        return $settings;
    }
}